﻿Module ModuleControls
	Sub GenerateListViewSearch(ByRef listview As ListView)
		listview.Items.Clear()
		listview.Columns.Clear()
		listview.Groups.Clear()
		listview.Activation = ItemActivation.TwoClick

		Dim columnName As New Windows.Forms.ColumnHeader()
		Dim columnArtistName As New Windows.Forms.ColumnHeader()
		Dim columnAlbumName As New Windows.Forms.ColumnHeader()
		Dim columnMBID As New Windows.Forms.ColumnHeader()

		columnName.Name = "Name"
		columnName.Text = columnName.Name
		columnName.Tag = columnName.Name
		columnName.Width = 200

		columnArtistName.Name = "Artist Name"
		columnArtistName.Text = columnArtistName.Name
		columnArtistName.Tag = columnArtistName.Name
		columnArtistName.Width = 120

		columnAlbumName.Name = "Album Name"
		columnAlbumName.Text = columnAlbumName.Name
		columnAlbumName.Tag = columnAlbumName.Name
		columnAlbumName.Width = 120

		columnMBID.Name = "MBID"
		columnMBID.Text = columnMBID.Name
		columnMBID.Tag = columnMBID.Name
		columnMBID.Width = 100

		Dim groupArtists As New ListViewGroup("Artists", "Artists")
		Dim groupAlbums As New ListViewGroup("Albums", "Albums")
		Dim groupTracks As New ListViewGroup("Tracks", "Tracks")

		groupArtists.Tag() = "Artists"
		groupAlbums.Tag() = "Albums"
		groupTracks.Tag() = "Tracks"

		listview.Columns.AddRange({columnName, columnArtistName, columnAlbumName, columnMBID})
		listview.Groups.AddRange({groupArtists, groupAlbums, groupTracks})

		listview.SmallImageList = New ImageList()
		listview.SmallImageList.ImageSize = New Size(50, 50)
		listview.SmallImageList.Images.Add(My.Resources.image_unavailable01)
	End Sub

	Function GenerateListViewItemSearch(name As String, artistName As String, albumName As String, mbid As String, imageindex As Integer, ByRef group As ListViewGroup) As ListViewItem

		Dim subItemName As New ListViewItem.ListViewSubItem()
		Dim subItemArtist As New ListViewItem.ListViewSubItem()
		Dim subItemAlbum As New ListViewItem.ListViewSubItem()
		Dim subItemMBID As New ListViewItem.ListViewSubItem()

		subItemName.Tag = "Name"
		subItemName.Name = subItemName.Tag
		subItemName.Text = name

		subItemArtist.Tag = "Artist Name"
		subItemArtist.Name = subItemArtist.Tag
		subItemArtist.Text = artistName

		subItemAlbum.Tag = "Album Name"
		subItemAlbum.Name = subItemAlbum.Tag
		subItemAlbum.Text = albumName

		subItemMBID.Tag = "MBID"
		subItemMBID.Name = subItemMBID.Tag
		subItemMBID.Text = mbid

		Return New ListViewItem({subItemName, subItemArtist, subItemAlbum, subItemMBID}, imageindex, group)
	End Function
End Module
